﻿@{ 
    ViewBag.Title = "入库"; 
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    var rowData = {};
    var index = -1;
    var FAccountDate=@ViewBag.FAccountDate;
    $(function () {
        initControl();
        gridList1();
    });
    function initControl() {
        $("[date-control]").val(new Date().format("yyyyMM"));

        $("[date-control]").on("click", function () {
            WdatePicker({ dateFmt: 'yyyyMM', minDate: '2000-1', maxDate: '2050-12' });
        });

        $("[month-control]").on("click", function () {
            WdatePicker({ dateFmt: 'yyyyMM', minDate: '2000-1', maxDate: '2050-12' });
        });
        //切换
        $('.category').on("click", function () {
            var aa = $("input[type='radio'].category:checked").val();
            if (aa == '登记') {
                gridList1();
            }
            else {
                gridList2();
            }
        });
        //来料单位
        $("#txtqueryFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search:true
        });
        //容器编号
        $("#txtFContainerNO").bindSelect({
            url: "/BaseData/ZSJ_21_RQ_DatContainer/GetGridJson",
            id: "FContainerNO",
            text: "FContainerNO"
        });
        //台帐日期赋初值
        $("#txtqueryFAccountDate").val(FAccountDate);
    }

    function gridList1() {
        $("#grid1").show();
        $("#grid2").hide();
        $(".rsider .active").show();
        $(".rsider .arc_show").hide();
        var $gridList = $("#gridList1");
        $gridList.dataGridForJson({
            url: "/VBaseData/V_CPK_42_MX_StoCPKListAcco/GetInStockInfos",//入库主界面显示
            height: $(window).height() - 130,
            colModel: [
                    { label: "id", name: "FDocuListID", width: 120, align: 'center', hidden: true },
                    { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
                    { label: '发生方式', name: 'FDocuTypeName', width: 80, align: 'left' },
                    { label: '单据编号', name: 'FDocuNO', width: 150, align: 'left' },
                    { label: '单据日期', name: 'FCurDate', width: 80, align: 'center' },
                    { label: "来料单位", name: "FProCompanyNO", width: 80, align: 'left' },
                    { label: "来料单位名称", name: "FProCompanyName", width: 120, align: 'left' },
                    { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left' },
                    { label: '零件名称', name: 'FProductionName', width: 140, align: 'left' },
                    { label: '开票数量', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
                    { label: '零件单价(元)', name: 'FPrice_KP', width: 80, align: 'right' },
                    { label: '金额(元)', name: 'FAmount_KP', width: 60, align: 'right' },
                    { label: '批次号', name: 'FBatchNo', width: 140, align: 'left' },
                    { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
                    { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
                    { label: '容器数量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '标准装箱数', name: 'FContent', width: 70, align: 'right' },
                    { label: '实际装箱数', name: 'FFactContent', width: 70, align: 'right' },
                    { label: '托盘编号', name: 'FPalletNO', width: 60, align: 'left' },
                    { label: '托盘数量', name: 'FPalletQuantity', width: 60, align: 'right' },
                    { label: '实际容量', name: 'FContainerNO', width: 60, align: 'right' },
                    { label: '标准容量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '开票总数', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际总数', name: 'FQuantity', width: 60, align: 'right' },
                    { label: '开票总价(元)', name: 'FAmount_KP', width: 80, align: 'right' },
                    { label: '实际总价(元)', name: 'FAmount', width: 80, align: 'right' },
                    { label: '凭证编号', name: 'FCredence', width: 80, align: 'left' },
                    { label: '备注', name: 'FDescription', width: 80, align: 'left' },
                    { label: '供货单位', name: 'FProductionTypeNO', width: 80, align: 'left' },
                    { label: '供货单位名称', name: 'FProductionTypeName', width: 100, align: 'left' },
                    { label: '零件分类编码', name: 'FProductionTypeNO', width: 60, align: 'left',hidden:true },
                    { label: '零件分类', name: 'FProductionTypeName', width: 60, align: 'left' },
                    { label: '仓库编号', name: 'FStoreNO', width: 60, align: 'left' },

                    { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left' },
                    { label: '定置编号', name: 'FStoreSetNO', width: 80, align: 'left' },

                    { label: '来料单位', name: 'FSupplierNO', width: 80, align: 'left' },
                    { label: '来料单位名称', name: 'FSupplierName', width: 100, align: 'left' },
                    { label: '存储卡号', name: 'FSourceDouNO', width: 80, align: 'left' },
                    { label: '送检单号', name: 'FCheckBillCode', width:120, align: 'left' },


                    { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left' },
                    { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
                    { label: '输入时间', name: 'FCreateTime', width: 60, align: 'center' },

                    { label: '审核人', name: 'FAuditingBy', width: 80, align: 'left' },
                    { label: '审核日期', name: 'FAuditingDate', width: 80, align: 'center' },
                    { label: '审核时间', name: 'FAuditingTime', width: 60, align: 'center' },
            ],
            pager: "#gridPager1",
            sortname: 'FDocuNO desc',
            viewrecords: true,
            rowNum:50,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
            }
        });
        $("#btn_search").click(function () {
            query($gridList);
        });
        $("#selectAll").click(function (e) {
            $("input[name='checkbox']").prop("checked", this.checked);
            e.stopPropagation();
        });
    }

    function btn_operration_Edit() {
        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
    }

    function query(obj) {
        obj.jqGrid('setGridParam', {
            postData: { companyno: $("#txtqueryFProCompanyNO").val(), productionno: $("#txtqueryFProductionNO").val(), fcurdate: $("#txtqueryFCurDate").val(), fcredence:$("#txtqueryFCredence").val(),faccountDate:$("#txtqueryFAccountDate").val()}
        }).trigger('reloadGrid');
    }

    function btn_Edit() {
        $.each(rowData, function (key, value) {
            if ($("#txt" + key).val()) {
                rowData[key] = $("#txt" + key).val();
            }
        });
        var fqty=$("#txtFQuantity").val();
        var FactContentQty=$("#txtFFactContent").val();
        if(FactContentQty>0){
            rowData["FContainerQuantity"]=Math.ceil(fqty/FactContentQty);
        }
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/EditInStoreDetail",
            param: rowData,
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    

    function btn_Audit() {
        var dataArray = [];
        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            dataArray.push($("#gridList1").jqGrid('getRowData', rowid).FDocuNO);
        });
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/AuditInStoreItem",
            param: { datas: JSON.stringify(dataArray) },
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_Cancel() {

        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
        $.each(rowData, function (key, value) {
            rowData[key] = "";
            $("#txt" + key).val("");
        });
    }

    //入库档案界面显示
    function gridList2() {
        $("#grid1").hide();
        $("#grid2").show();
        $(".rsider .active").hide();
        $(".rsider .arc_show").show();
        var $gridList = $("#gridList2");
        var url="/VBaseData/V_CPK_45_HZ_StoCPKListAcco_Mid/StoInCPKMidList";
        var queryFAccountDate=$("#txtqueryFAccountDate").val();
        if( queryFAccountDate!=FAccountDate){
            url="/VBaseData/V_CPK_45_HZ_StoCPKListAcco_Mid/StoInCPKMidList";
        }
        $gridList.dataGridForJson({
            url:url,
            height: $(window).height() - 130,
            colModel: [
                    { label: "id", name: "FDocuListID", width: 120, align: 'center', hidden: true },
                    { label: '<input id="selectAllArc" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
                    { label: '发生方式', name: 'FDocuTypeName', width: 80, align: 'left' },
                    { label: '单据编号', name: 'FDocuNO', width: 150, align: 'left' },
                    { label: '单据日期', name: 'FCurDate', width: 80, align: 'left' },
                    { label: "来料单位", name: "FProCompanyNO", width: 80, align: 'left' },
                    { label: "来料单位名称", name: "FProCompanyName", width: 120, align: 'left' },
                    { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left' },
                    { label: '零件名称', name: 'FProductionName', width: 140, align: 'left' },
                    { label: '开票数量', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
                    { label: '零件单价(元)', name: 'FPrice_Settle', width: 80, align: 'right' },
                    { label: '金额(元)', name: 'FMoney_Settle', width: 60, align: 'right' },
                    { label: '批次号', name: 'FBatchNo', width: 140, align: 'left' },
                    { label: '托盘编号', name: 'FPalletNO', width: 60, align: 'center' },
                    { label: '托盘数量', name: 'FPalletQuantity', width: 60, align: 'right' },
                    { label: '实际容量', name: 'FContainerNO', width: 60, align: 'right' },
                    { label: '标准容量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
                    { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
                    { label: '容器数量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '标准装箱数', name: 'FContent', width: 70, align: 'right' },
                    { label: '实际装箱数', name: 'FFactContent', width: 70, align: 'right' },

                    { label: '开票总数', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际总数', name: 'FQuantity', width: 60, align: 'right' },
                    { label: '开票总价(元)', name: 'FAmount_KP', width: 80, align: 'right' },
                    { label: '实际总价(元)', name: 'FAmount', width: 80, align: 'right' },
                    { label: '凭证编号', name: 'FCredence', width: 80, align: 'left' },

                    { label: '备注', name: 'FDescription', width: 80, align: 'left' },
                    { label: '供货单位', name: 'FSupplierNO', width: 80, align: 'left' },
                    { label: '供货单位名称', name: 'FSupplierName', width: 100, align: 'left' },
                    { label: '零件分类', name: 'FProductionTypeNO', width: 60, align: 'left' },

                    { label: '仓库编号', name: 'FStoreNO', width: 60, align: 'left' },
                    { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left' },
                    { label: '定置编号', name: 'FStoreSetNO', width: 80, align: 'left' },

                    { label: '存储卡号', name: 'FSourceDouNO', width: 130, align: 'left' },
                    { label: '送检单号', name: 'FCheckBillCode', width: 80, align: 'left' },

                    { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left' },
                    { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
                    { label: '输入时间', name: 'FCreateTime', width: 60, align: 'center' },

                    { label: '审核人', name: 'FAuditingBy', width: 80, align: 'left' },
                    { label: '审核日期', name: 'FAuditingDate', width: 80, align: 'center' },
                    { label: '审核时间', name: 'FAuditingTime', width: 80, align: 'center' },
            ],
            pager: "#gridPager2",
            sortname: 'FDocuNO desc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
            }
        });

        $("#btn_search").click(function () {
            query($gridList);
        });
        $("#selectAllArc").click(function (e) {
            $("input[name='checkbox']").prop("checked", this.checked);
            e.stopPropagation();
        });
    }

    function btn_Ok() {
        $.each(rowData, function (key, value) {
            rowData[key] = $("#txt" + key).val();
        });
        $("#gridList1").jqGrid('setRowData', index, rowData);
    }

    function btn_Add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/EnterWareHouse/WareHouseEnterInput"
        });
    }

    function btn_Del() {
        var postData = [];
        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            postData.push($("#gridList1").jqGrid('getRowData', rowid).FDocuListID);
        });
        $.deleteForm({
            url: "/WareHouse/EnterWareHouse/DeleteInStoreItem",
            param: { datas: JSON.stringify(postData) },
            success: function () {
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    //冲红
    function btn_WriteOff(){
        debugger
        var rowData = $("#gridList2").jqGrid('getRowData', index);
        if (rowData.FDocuListID != undefined) {
            $.modalConfirm("注：您确定要【冲红】该条数据吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WareHouse/EnterWareHouse/WriteOffInStoreItem",
                        param: { keyValue: rowData.FDocuListID },
                        success: function () {
                            gridList2();
                        }
                    })
                }
            });
        } else {
            $.modalAlert("注：您没有选中任何行。", "warning");
        }
    }
    //打印入库单

    function btn_Print() {
        var dataArray = [];
        var flag = "reg";
        var aa = $("input[type='radio'].category:checked").val();
        if (aa == '登记') {
            $("#gridList1 input:checkbox:checked").each(function () {
                var rowid = $(this).attr("value");
                var docuNo=$("#gridList1").jqGrid('getRowData', rowid).FDocuNO;
                if($.inArray(docuNo, dataArray)==-1){
                    dataArray.push(docuNo);
                }
            });
        } else {
            $("#gridList2 input:checkbox:checked").each(function () {
                var rowid = $(this).attr("value");
                var docuNo=$("#gridList2").jqGrid('getRowData', rowid).FDocuNO;
                if($.inArray(docuNo, dataArray)==-1){
                    dataArray.push(docuNo);
                }
            });
            flag = "arc";//档案
        };
        $.detailOpen({
            id: "PrintStorgeCard",
            title: "",
            url: "/WareHouse/EnterWareHouse/PrintStockIn?flag=" + flag + "&data=" + dataArray.join(',')
        });
    }
</script>

   <div><input id="txtFDocuListID" name="FDocuListID" type="hidden" /></div>

    <div class="functionHeader" style="width:100%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px; border-bottom:2px solid #CCC;">
        <div class="lsider">
            <div class="updowninput btn-group" style="margin-top:10px;">
                <input id="radio11" class="category" name="category" value="登记" checked="checked" type="radio"><label for="radio11" class="suffix">登记</label><br>
                <input id="radio12" class="category" name="category" value="档案" type="radio"><label for="radio12" class="suffix">档案</label>
            </div>
            <div class="updowninput" style="width:180px;height:20px;margin-left:10px;">
                <p>来料单位</p>
                <select id="txtqueryFProCompanyNO" class="form-control">
                    <option value="">==请选择==</option>
                </select>
            </div>
            <div class="updowninput">
                <p>零件编号</p>                
                <input id="txtqueryFProductionNO"  type="text" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>来料日期</p>
                <input id="txtqueryFCurDate"  type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker()" />
                &nbsp;
            </div>
            <div class="updowninput">
                <p>凭证编号</p>
                <input id="txtqueryFCredence" type="text" class="form-control required" value="" />
            </div>
            <div class="updowninput" style="width:100px;margin-left:10px;">
                <p>台账日期</p>
                <input id="txtqueryFAccountDate"  type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyyMM', isShowToday: false, isShowClear: false });" />
                &nbsp;
            </div>
            <div class="btn-group" style="margin-top:12px;margin-left:10px;">
                &nbsp;
                <a id="btn_search" class="btn btn-primary center-block" ><span class="glyphicon glyphicon-search"></span>  &nbsp; 查询</a>
            </div>
        </div>

        <div class="rsider">
            <div class="btn-group btn-operration" style="float:right;margin-top:12px;">
                <a class="btn btn-primary center-block" onclick="$.reload()">  <span class="glyphicon glyphicon-refresh"> </span>&nbsp刷新</a>
                <a class="btn btn-primary center-block active" onclick="btn_Add()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp输入</a>
                <a class="btn btn-primary center-block active" onclick="btn_Del()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp删除</a>
                <a class="btn btn-primary center-block active" onclick="btn_operration_Edit()">  <span class="glyphicon glyphicon-plus">    </span>&nbsp修改</a>
                <a class="btn btn-primary center-block active" onclick="btn_Audit()">  <span class="glyphicon glyphicon-plus">    </span>&nbsp审核</a>
                <a class="btn btn-primary center-block active" onclick="btn_List()">  <span class="glyphicon glyphicon-th-list">    </span>&nbsp单据</a>
                <a class="btn btn-primary center-block arc_show" style="display:none;" onclick="btn_WriteOff()">  <span class="glyphicon glyphicon-th-list"></span>&nbsp冲红</a>
                <a class="btn btn-primary center-block" onclick="btn_Print()"> <span class="glyphicon glyphicon-print">   </span>&nbsp打印</a>
                <a class="btn btn-primary center-block" onclick="btn_Excel()"> <span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
            </div>
        </div>

        <div class="btn-group btn-edit-entity" style="float:left;margin-top:12px;display:none;">
            <a class="btn btn-primary center-block" onclick="btn_Edit();">   <span class="glyphicon "></span>修改</a>
            <a class="btn btn-primary center-block" onclick="btn_Cancel();"><span class="glyphicon "></span>关闭</a>
        </div>

    </div>

    <form id="form">
    <table id="eidt_entity" class="form" style="width:600px;display:none; margin:0 80px; text-align:left;">
        <tr>
            <th class="formTitle">单据编号</th>
            <td class="formValue">
                <input id="txtFDocuNO" name="FDocuNO" style="width:140px;" readonly="readonly" class="form-control" type="text">
            </td>
            <th class="formTitle">容器编号</th>
            <td class="formValue" style="width:140px;" >
                <input id="txtFContainerNO" name="FContainerNO" style="width:140px;" readonly="readonly" class="form-control" type="text">
            </td>
            <th class="formTitle">实际装箱数</th>
            <td class="formValue">
                <input id="txtFFactContent" name="FFactContent" style="width:140px;" class="form-control" type="text">
            </td>
        </tr>
        <tr>
            <th class="formTitle">零件编号</th>
            <td class="formValue">
                <input id="txtFProductionNO" name="FProductionNO" style="width:140px;" readonly="readonly" class="form-control" type="text">
            </td>
            <th class="formTitle">实际数量</th>
            <td class="formValue" >
                <input id="txtFQuantity" name="FQuantity" style="width:140px;" class="form-control" type="text">
            </td>
            <th class="formTitle">零件单价</th>
            <td class="formValue">
                <input id="txtFPrice_KP" name="FPrice_KP" style="width:140px;" class="form-control" type="text">
            </td>
        </tr>
    </table>
    </form>

    <div id="grid1">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>

    <div id="grid2">
        <table id="gridList2"></table>
        <div id="gridPager2"></div>
    </div>
   